package com.chief;

import com.chief.service.TccTestService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.math.BigDecimal;

@RefreshScope
@DubboService
public class TallServiceImpl implements TallService {

    @Autowired
    private AccountService accountService;
    @DubboReference
    private GoodsTestService goodsTestService;
    @DubboReference
    private OrderTestService orderTestService;

    @DubboReference
    private TccTestService tccTestService;


    @Value("${a}")
    String name;

    @Override
    public String config() {
        return name;
    }


    @GlobalTransactional
    @Override
    public void cut(Integer index) {
        for (int i = 1; i <= index; i++) {
            System.out.println("iiiiiiiiiiiiiiiii-->" + i);
            this.accountService.reduce(Double.valueOf("" + i));
            this.orderTestService.create("title-" + i, i);
            this.tccTestService.prepare(null, 1, BigDecimal.valueOf(9.9), i);
        }
    }
}
